<template>
  <div>
    <!-- 查询条件-->
    <el-form :inline="true" :model="SearchDate" class="demo-form-inline">
      <el-form-item label="置业顾问">
        <el-select v-model="SearchDate.eid" placeholder="置业顾问">
          <el-option
            :label="emp.ename"
            :value="emp.eid"
            v-for="emp in AllEmp"></el-option>
        </el-select>
      </el-form-item>

    <span class="demonstration">选择日期</span>
    <el-date-picker
      v-model="value2"
      type="daterange"
      align="right"
      unlink-panels
      range-separator="至"
      start-placeholder="开始日期"
      end-placeholder="结束日期"
      :picker-options="pickerOptions">
    </el-date-picker>


      <el-form-item>
        <el-button type="primary" @click="toSearch">查询</el-button>
      </el-form-item>
    </el-form>

    <!-- 列表展示 -->
    <el-table :data="tableData" style="width: 100%">
      <el-table-column label="#" width="80">
        <!-- <template slot-scope="scope"> -->
        <span style="margin-left: 10px"><el-checkbox></el-checkbox></span>
        <!-- </template> -->
      </el-table-column>

      <el-table-column label="客户名" width="180">
        <template slot-scope="scope">
          <i class="el-icon-time"></i>
          <span style="margin-left: 10px">{{ scope.row.uname }}</span>
        </template>
      </el-table-column>

      <el-table-column label="置业顾问" width="180">
        <template slot-scope="scope">
          <span style="margin-left: 10px">{{ scope.row.ename }}</span>
        </template>
      </el-table-column>

      <el-table-column label="房间" width="180">
        <template slot-scope="scope">
          <span style="margin-left: 10px">{{ scope.row.hunm }}</span>
        </template>
      </el-table-column>

      <el-table-column label="成交价" width="180">
        <template slot-scope="scope">
          <span style="margin-left: 10px">{{ scope.row.money }}</span>
        </template>
      </el-table-column>

      <el-table-column label="生成日期" width="180">
        <template slot-scope="scope">
          <span style="margin-left: 10px">{{ scope.row.stime }}</span>
        </template>
      </el-table-column>
    </el-table>

    <!-- 分页 -->

    <el-pagination
      background
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page="currentPage"
      :page-sizes="[3, 6, 9, 11]"
      :page-size="pageSize"
      layout="total, sizes, prev, pager, next, jumper"
      :total="totalPage"
    >
    </el-pagination>
  </div>
</template>

<script>
export default {
  data() {
    return {
      // 查询条件数据
      SearchDate: {
        eid: "",
        begin: "",
        end: "",
      
      },
      //所有员工
      AllEmp: [],
      // 列表展示数据
      tableData: [],
      // 分页数据
      totalPage: 0,
      pageSize: "",
      currentPage: "",
      //日期选择
      pickerOptions: {
          shortcuts: [{
            text: '最近一周',
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
              picker.$emit('pick', [start, end]);
            }
          }, {
            text: '最近一个月',
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
              picker.$emit('pick', [start, end]);
            }
          }, {
            text: '最近三个月',
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 90);
              picker.$emit('pick', [start, end]);
            }
          }]
        },
        value1: '',
        value2: ''
    };
  },
  created() {
    this.currentPage = 1;
    this.pageSize = 3;
    this.showList();
    this.showEmp();
  },
  methods: {
    //加载员工列表
    showEmp(){
      this.$axios.get("/ever-emp/findAllNoPage/","")
      .then(res => {
        this.AllEmp=res.data
        
      })
      .catch(err => {
        console.error(err); 
      })

    },
    //查询条件方法和所有数据
    showList() {
      console.log(this.currentPage)
      console.log(this.pageSize)
      this.$axios
        .post(
          "/ever-salerecord/ManagerFindAllSL/" +
            this.currentPage +
            "/" +
            this.pageSize +
            "?foo=" +
            new Date().getTime(),
          {
            eid: this.SearchDate.eid,
            begin: this.value2[0],
            end: this.value2[1],
          }
        )
        .then((res) => {
          this.loading = false;
          this.totalPage = parseInt(res.data.totalPage);
          this.tableData = res.data.list;
          
        })
        .catch((err) => {
          console.error(err);
        });
    },

    //查询条件方法
    toSearch() {
      this.showList();
      console.log(this.value2[0]);
    },
    // 列表展示方法
    handleEdit(index, row) {
      console.log(index, row);
    },
    handleDelete(index, row) {
      console.log(index, row);
    },
    // 分页方法
    handleSizeChange(val) {
      this.pageSize = val;
      this.showList();
      console.log(val);
      console.log(this.pageSize);
      console.log(`每页 ${val} 条`);
    },
    handleCurrentChange(val) {
      this.currentPage = val;
      this.showList();
      console.log(`当前页: ${val}`);
    },
  },
};
</script>
